<script type="text/javascript">
$(function() {
	var pg = App.auth.sysUserEdit.ui;
	pg.params = pg.params || { status: '0' };
	var frm = {
		id: pg.seek('id'),
		nick: pg.seek('nick'),
		name: pg.seek('name'),
		email: pg.seek('email'),
		phone: pg.seek('phone'),
		corpId: pg.seek('corpId'),
		deptId: pg.seek('deptId'),
		memo: pg.seek('memo'),
		status: pg.seek('status')
	}
	
	frm.status.mac('combo', {
		keyField: 'k',
		displayField: 'v',
		multiSelect: false,
		width: 80,
		boxWidth: 81,
		cols : [{
			field: 'v', width: 80
		}],
		data: [{ k: 0, v: '未启用' }, { k: 1, v: '已启用' }]
	});
	
	function getValues(){
		return {
			id: frm.id.val(),
			nick: frm.nick.val(),
			name: frm.name.val(),
			email: frm.email.val(),
			phone: frm.phone.val(),
			corpId: frm.corpId.val(),
			deptId: frm.deptId.val(),
			status : frm.status.selected[0], // 0未启用，1启用
			memo: frm.memo.val()
		};
	}
	
	function setValues(o){
		pg.children('.title').html(o.id? '编辑人员信息':'添加人员');
		frm.id.val(o.id);
		frm.nick.val(o.nick);
		frm.name.val(o.name);
		frm.email.val(o.email);
		frm.phone.val(o.phone);
		frm.corpId.val(o.corpId);
		frm.deptId.val(o.deptId);
		frm.status.select(o.status+''); // 0未启用，1启用
		frm.memo.val(o.memo);
	}
	
	function valid(p){
		var x = App.validate, v = App.base.validation,
		msg=pg.seek('msg').html('');

		return !x(v.admin.nick, p.nick, msg, '人员昵称') && 
			   !x(v.admin.name, p.name, msg, '人员姓名') &&
			   !x(v.common.status, p.status, msg, '状态') &&
			   !x(v.common.email, p.email, msg,'Email') &&
			   !x(v.common.phone, p.phone, msg,'电话') ;
	}
	
	pg.find('input').blur(function() {
		var pms = getValues();
		if (!valid(pms))
			return;
	});
	
	pg.seek('ok').click(function(){
		var pms = getValues();
		if(!valid(pms))
			return false;
		$.post(App.auth.ctx + '/sys/user/save.do', pms, function(data){
			var ro = mac.eval(data);
			if(ro.success){
				pg.callback();
				pg.close();
			}else{
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	
	pg.seek('cancel').click(function(){
		pg.close();
	});
	
	if(pg.params.code){
		frm.code.prop('readonly', 'readonly').css('border', 'none');
	}
	
	setValues(pg.params);
});
</script>
<div class="form">
	<h3 class="title hidden">编辑人员</h3>
	<input type="hidden" name="id" /> <input type="hidden" name="corpId" />
	<input type="hidden" name="deptId" />
	<div class="item">
		<span class="label">人员昵称</span> <input type="text" name="nick" /> <span
			class="msg">*</span>
	</div>
	<div class="item">
		<span class="label">人员姓名</span> <input type="text" name="name" /> <span
			class="msg">*</span>
	</div>
	<div class="item">
		<span class="label">状态</span>
		<div class="combo fl" name="status"></div>
		<span class="msg">*</span>
	</div>
	<div class="item">
		<span class="label">Email</span> <input type="text" name="email" /> <span
			class="msg">*</span>
	</div>
	<div class="item">
		<span class="label">电话</span> <input type="text" name="phone" /> <span
			class="msg">*</span>
	</div>
	<div class="item">
		<span class="label">备注</span>
		<textarea name="memo"></textarea>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg" class="msg"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">保存</button>
		<button name="cancel">取消</button>
	</div>
</div>